package com.xudu.controller.impl;

import com.xudu.common.Result;
import com.xudu.controller.IFileController;
import com.xudu.entity.User;
import com.xudu.service.IFileService;
import com.xudu.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * ClassName: IFileControllerImpl
 * Description:
 *
 * @Author xudu
 * @Create 2024/4/21
 */
@Slf4j
@RequestMapping("/file")
@RestController
public class FileControllerImpl implements IFileController {

    @Autowired
    private IFileService iFileService;

    @Override
    public Result savePhoto(User user, MultipartFile photo) {
        boolean b = iFileService.uploadPhoto(user, photo);
        if (b){
            return Result.success(user);
        }else {
            return Result.error("图片上传失败！");
        }

    }

    @Override
    public Result getPhoto(User user, HttpServletResponse response) {
        iFileService.downloadPhoto(user,response);
        return Result.success();
    }
}
